package com.zx.mes.hyl.security.core.validate.code;

import com.zx.mes.hyl.security.core.validate.code.exception.ValidateCodeException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;


import java.util.Map;

/**
 * 校验码处理器 管理器
 * @author huayunlong
 * @date 2018-6-2
 */
public class ValidateCodeProcessorManager {

    private Logger logger= LoggerFactory.getLogger(getClass());

    @Autowired
    private Map<String,ValidateCodeProcessor> validateCodeProcessors;

    public ValidateCodeProcessor findValidateCodeProcessor(ValidateCodeType type){
        return findValidateCodeProcessor(type.toString().toLowerCase());
    }

    public ValidateCodeProcessor findValidateCodeProcessor(String type) {
        String name=type.toLowerCase()+ValidateCodeProcessor.class.getSimpleName();
        logger.info("校验处理器:[{}]",name);
        ValidateCodeProcessor processor=validateCodeProcessors.get(name);
        if (processor == null){
            throw new ValidateCodeException("验证码处理器" + name + "不存在");
        }

        return processor;
    }
}
